package com.LoginTest;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@WebServlet("/ls")
public class LServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置请求乱码
        req.setCharacterEncoding("utf-8");
        //设置响应乱码
        resp.setContentType("text/html;charset=utf-8");

        String username = req.getParameter("username");
        System.out.println(username);

        //获取输入的用户名存入
        req.setAttribute("name",username);

        if ( username.equals("张三")){
            RequestDispatcher ys = req.getRequestDispatcher("/ys");
            ys.forward(req,resp);
        }else {
            RequestDispatcher ns = req.getRequestDispatcher("/ns");
            ns.forward(req,resp);
        }
    }
}
